refactor(rust): share test scaffolding via mergify-test-support crate#1439
Conversation
|
This pull request is part of a Mergify stack:
|
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 ⛓️ Depends-On RequirementsWaiting for
This rule is failing.Requirement based on the presence of
🔴 👀 Review RequirementsWaiting for
This rule is failing.
🔴 🔎 ReviewsWaiting for
This rule is failing.
🟢 🤖 Continuous IntegrationWonderful, this rule succeeded.
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 📕 PR descriptionWonderful, this rule succeeded.
|
721eacd to
a6bf822
Compare
32628b4 to
d7feae3
Compare
Revision history
|
d7feae3 to
bdea5bb
Compare
a6bf822 to
ac72c27
Compare
53fc9fd to
d62619b
Compare
|
@jd this pull request is now in conflict 😩 |
d62619b to
d61820b
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the Rust workspace’s test code by extracting repeated output-capture scaffolding (shared buffers + Write adapters + helpers) into a dedicated mergify-test-support crate that is only used via dev-dependencies, reducing boilerplate and keeping test-only types out of production builds.
Changes:
- Added a new
crates/mergify-test-supportcrate providingCaptured,SharedBytes, andSharedWriterfor consistent stdout/stderr capture in tests. - Updated multiple command-crate test modules to use
mergify_test_support::Capturedinstead of local duplicated implementations. - Wired the new crate into relevant crates’
dev-dependenciesand updatedCargo.lock.
Reviewed changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/mergify-test-support/src/lib.rs | Introduces shared capture types (Captured, SharedWriter) for Rust command tests. |
| crates/mergify-test-support/Cargo.toml | Defines the new non-published test-support crate and its dependency on mergify-core. |
| crates/mergify-queue/src/unpause.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-queue/src/status.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-queue/src/show.rs | Replaces local capture scaffolding in tests with Captured and removes dead-code stderr accessor workaround. |
| crates/mergify-queue/src/pause.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-queue/Cargo.toml | Adds mergify-test-support under dev-dependencies. |
| crates/mergify-freeze/src/update.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-freeze/src/list.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-freeze/src/delete.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-freeze/src/create.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-freeze/Cargo.toml | Adds mergify-test-support under dev-dependencies. |
| crates/mergify-config/src/validate.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-config/src/simulate.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-config/Cargo.toml | Adds mergify-test-support under dev-dependencies. |
| crates/mergify-ci/src/scopes_send.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-ci/src/queue_metadata.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-ci/src/queue_info.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-ci/src/git_refs.rs | Replaces local capture scaffolding in tests with Captured. |
| crates/mergify-ci/Cargo.toml | Adds mergify-test-support under dev-dependencies. |
| Cargo.lock | Records the new crate and dependency edges in the workspace lockfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Every command crate's test module re-rolled the same ~30 LOC of `SharedBytes` / `SharedWriter` / `Captured` / `make_output` glue — about 350 LOC of pure boilerplate across 15 files, drifting over time (some `Captured` had `stderr`, some didn't; one file even carried a `_stderr_accessor_lives` dead-code stub just to silence the resulting warning). Extract the canonical version into a new `mergify-test-support` crate that other crates pull in as a `dev-dependencies`. The new `Captured` API exposes `human()` / `new(mode)` constructors and `stdout()` / `stderr()` accessors, so the common pattern shrinks from a 12-line `String::from_utf8(cap.stdout.lock().unwrap().clone())` to `let s = cap.stdout()`. Net `-418 / +114` lines across the workspace. Behavior unchanged; all 233 tests pass. The crate is `publish = false` and only ever appears under `[dev-dependencies]`, so the test-only types never leak into a production build. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Change-Id: If9d688cdaf55360ba90f386d2020b52346c19b28
83fc4d3 to
fe3d611
Compare
d61820b to
32a71f8
Compare
Every command crate's test module re-rolled the same ~30 LOC of
SharedBytes/SharedWriter/Captured/make_outputglue —about 350 LOC of pure boilerplate across 15 files, drifting over
time (some
Capturedhadstderr, some didn't; one file evencarried a
_stderr_accessor_livesdead-code stub just to silencethe resulting warning).
Extract the canonical version into a new
mergify-test-supportcrate that other crates pull in as a
dev-dependencies. The newCapturedAPI exposeshuman()/new(mode)constructors andstdout()/stderr()accessors, so the common pattern shrinksfrom a 12-line
String::from_utf8(cap.stdout.lock().unwrap().clone())to
let s = cap.stdout().Net
-418 / +114lines across the workspace. Behavior unchanged;all 233 tests pass.
The crate is
publish = falseand only ever appears under[dev-dependencies], so the test-only types never leak into aproduction build.
Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com
Depends-On: #1464